<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="手机号">
            <el-input v-model="form.phone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="省">
            <el-input v-model="form.province" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="市">
            <el-input v-model="form.city" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="县">
            <el-input v-model="form.county" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="升数">
            <el-input v-model="form.litre" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="大呷卡用户消费订单ID">
            <el-input v-model="form.consumerOrderId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单号">
            <el-input v-model="form.orderId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付号">
            <el-input v-model="form.paySn" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单生成时间, 时间格式2017-09-27 00:00:00">
            <el-input v-model="form.orderTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付时间, 时间格式2017-09-27 00:00:00">
            <el-input v-model="form.payTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退款时间, 时间格式2017-09-27 00:00:00">
            <el-input v-model="form.refundTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="油站名称">
            <el-input v-model="form.gasName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="枪号">
            <el-input v-model="form.gunNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="油号">
            <el-input v-model="form.oilNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="实付金额(单位:元)">
            <el-input v-model="form.amountPay" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单总金额(单位:元)">
            <el-input v-model="form.amountGun" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="优惠金额(单位:元)">
            <el-input v-model="form.amountDiscounts" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单状态">
            <el-input v-model="form.orderStatusName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="优惠券金额(单位:元)">
            <el-input v-model="form.couponMoney" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="优惠券 Id">
            <el-input v-model="form.couponId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="优惠券 Code">
            <el-input v-model="form.couponCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付方式">
            <el-input v-model="form.payType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="最终享受单价(单位:元)">
            <el-input v-model="form.priceUnit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="国标价(单位:元)">
            <el-input v-model="form.priceOfficial" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="枪价 (单位:元)">
            <el-input v-model="form.priceGun" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('consumerOrderId')" prop="consumerOrderId" label="大呷卡用户消费订单ID" />
        <el-table-column v-if="columns.visible('orderId')" prop="orderId" label="订单号" />
        <el-table-column width="100" v-if="columns.visible('phone')" prop="phone" label="手机号" />
        <el-table-column v-if="columns.visible('gasName')" prop="gasName" label="油站名称" />
        <el-table-column v-if="columns.visible('gunNo')" prop="gunNo" label="枪号" />
        <el-table-column v-if="columns.visible('oilNo')" prop="oilNo" label="油号" />
        <el-table-column v-if="columns.visible('province')" prop="province" label="省" />
        <el-table-column v-if="columns.visible('city')" prop="city" label="市" />
        <el-table-column v-if="columns.visible('county')" prop="county" label="县" />
        <el-table-column v-if="columns.visible('litre')" prop="litre" label="升数" />
        <el-table-column v-if="columns.visible('amountPay')" prop="amountPay" label="实付金额(单位:元)" />
        <el-table-column v-if="columns.visible('amountGun')" prop="amountGun" label="订单总金额(单位:元)" />
        <el-table-column v-if="columns.visible('amountDiscounts')" prop="amountDiscounts" label="优惠金额(单位:元)" />
        <el-table-column v-if="columns.visible('orderStatusName')" prop="orderStatusName" label="订单状态" />
        <el-table-column v-if="columns.visible('couponMoney')" prop="couponMoney" label="优惠券金额(单位:元)" />
        <el-table-column v-if="columns.visible('couponId')" prop="couponId" label="优惠券 Id" />
        <el-table-column width="90" v-if="columns.visible('couponCode')" prop="couponCode" label="优惠券 Code" />
        <el-table-column v-if="columns.visible('payType')" prop="payType" label="支付方式" />
        <el-table-column width="100" v-if="columns.visible('priceUnit')" prop="priceUnit" label="最终享受单价(单位:元)" />
        <el-table-column width="70" v-if="columns.visible('priceOfficial')" prop="priceOfficial" label="国标价(单位:元)" />
        <el-table-column width="70" v-if="columns.visible('priceGun')" prop="priceGun" label="枪价 (单位:元)" />
        <el-table-column v-if="columns.visible('paySn')" prop="paySn" label="支付号" />
        <el-table-column width="100" v-if="columns.visible('orderTime')" prop="orderTime" label="订单生成时间" />
        <el-table-column v-if="columns.visible('payTime')" prop="payTime" label="支付时间" />
        <el-table-column v-if="columns.visible('refundTime')" prop="refundTime" label="退款时间" />
        <el-table-column v-permission="['admin','oilTuanyouOrder:edit','oilTuanyouOrder:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudOilTuanyouOrder from '@/api/oilTuanyouOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '团油订单', url: 'api/oilTuanyouOrder', sort: 'id,desc', crudMethod: { ...crudOilTuanyouOrder }})
const defaultForm = { id: null, unique: null, phone: null, province: null, city: null, county: null, litre: null, consumerOrderId: null, orderId: null, paySn: null, orderTime: null, payTime: null, refundTime: null, gasName: null, gunNo: null, oilNo: null, amountPay: null, amountGun: null, amountDiscounts: null, orderStatusName: null, couponMoney: null, couponId: null, couponCode: null, payType: null, priceUnit: null, priceOfficial: null, priceGun: null, orderSource: null, qrCode4PetroChina: null }
export default {
  name: 'OilTuanyouOrder',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {

      permission: {
        add: ['admin', 'oilTuanyouOrder:add'],
        edit: ['admin', 'oilTuanyouOrder:edit'],
        del: ['admin', 'oilTuanyouOrder:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'unique', display_name: 'unique' },
        { key: 'phone', display_name: '手机号' },
        { key: 'province', display_name: '省' },
        { key: 'city', display_name: '市' },
        { key: 'county', display_name: '县' },
        { key: 'litre', display_name: '升数' },
        { key: 'consumerOrderId', display_name: '大呷卡用户消费订单ID' }
      ]
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.id
        delete this.crud.params.unique
        delete this.crud.params.phone
        delete this.crud.params.province
        delete this.crud.params.city
        delete this.crud.params.county
        delete this.crud.params.litre
        delete this.crud.params.consumerOrderId
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
